package com.ls.system.mapper;


import com.ls.system.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ls
 * @since 2025-04-06
 */
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    @Select({
            "SELECT m.id, m.pid, m.title, m.icon, m.href, m.open, m.available, m.type",
            "FROM sys_role_user ru",
            "JOIN sys_role_menu rm ON ru.rid = rm.rid",
            "JOIN sys_menu m ON rm.pid = m.id",
            "WHERE ru.uid = #{userId}"
    })
    List<SysMenu> getMenusByUserId(@Param("userId") Integer userId);

    @Select("SELECT id, pid, title, icon, href, open, available, type " +
            "FROM sys_menu " +
            "WHERE available = 1 " +  // 只查询可用菜单
            "ORDER BY pid, id ASC")   // 按父子关系和ID排序
    List<SysMenu> selectAllAvailableMenus();
}
